#!/bin/bash

# remove the previous installation
./deploy1.sh_cleanup

bld=$(adapt query self bld)

# everything here would be in adapt, but I do not want to complicate now

cd $bld

installed=$(adapt query self installed)
fix=$(adapt oop self generate_fixes)
prev_fix=$(adapt query self fix)

echo fix = $fix prev = $pref_fix

# if the library is installed but a new solution is not found it fails
if [ x$installed == "xyes" -a "$fix" == "$prev_fix" ]
then
  # the fix is not known (empty) or is the same as before which means last fix did not work
  echo FIX not found
  exit 1
else
  echo FIX different, update applied fix
  adapt register lib/lifev "fix=$fix"
fi

adapt cmake \
  -D CMAKE_CXX_FLAGS=-DNDEBUG \
  -D CMAKE_BUILD_TYPE:STRING=RELEASE \
  -D CMAKE_INSTALL_PREFIX:PATH=$(adapt query sys/prefix) \
  -D LifeV_ENABLE_Core:BOOL=ON \
  ..

echo adapt cmake \
  -D CMAKE_CXX_FLAGS=-DNDEBUG \
  -D CMAKE_BUILD_TYPE:STRING=RELEASE \
  -D CMAKE_INSTALL_PREFIX:PATH=$(adapt query sys/prefix) \
  -D LifeV_ENABLE_Core:BOOL=ON \
  -D LifeV_ENABLE_NavierStokes:BOOL=ON \
  -D LifeV_ENABLE_Operator:BOOL=ON \
  -D LifeV_ENABLE_ECM2:BOOL=ON $fix \
  ..

#  -D Trilinos_DIR=/home/jaross/adapt/soft/lib/cmake/Trilinos \
adapt make -j $(adapt query sys/cpunum)

adapt make install

adapt register self installed=yes
